<template>
	<z-paging ref="paging" v-model="dataList" @query="queryList"
		:loading-more-custom-style="{ paddingBottom: 'env(safe-area-inset-bottom)' }">
		<template #top>
			<view class="zpagin_top">
				<nav-bar :iconLeft="true" />
				<view class="search">
					<custom-search v-model="queryParams.search" @search="refreshList" placeholder="请输入维修编号/主题" />
				</view>
			</view>
		</template>
		<uni-card v-for="item in dataList" :key="item.id" margin="0" spacing="0" @click="goDetail(item, pageUrl, '20204')">
			<template v-slot:title>
				<uni-list>
					<uni-list-item :title="item.code" :note="item.device_name" thumbSize="lg">
						<template v-slot:footer>
							<up-tag size="mini" :text="status_list[item.status_display].text" plain plainFill
								:type="status_list[item.status_display].type" />
						</template>
					</uni-list-item>
				</uni-list>
			</template>
			<view class="ctent">维修主题：{{ item.title }}</view>
			<view class="ctent">创建时间：{{ item.create_date }}</view>
			<view class="con">
				<view class="ctent">提交人：{{ item.create_full_name }}</view>
				<view class="ctent">接单人：{{ item.task_full_name }}</view>
			</view>
			<view class="ctent">接单时间：{{ item.task_date }}</view>
			<view class="con" style="align-items: normal;">
				<view class="ctent" style="flex: none;">备注：</view>
				<view class="ctent">{{ item.desc }}</view>
			</view>
			<view class="con_button" v-if="$hasPerm(['110405'])" v-show="item.status_display == '待接单'"
				@click.stop="hanldAct(item.id, 2, '接单成功')">
				接 单
			</view>
			<view class="con_button" v-if="$hasPerm(['110406'])" v-show="item.status_display == '维修中'"
				@click.stop="waitDetail(item.id)">
				维 修
			</view>
		</uni-card>
	</z-paging>
</template>
<script setup>
import { ref, reactive } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import deRepairApi from '../../../api/device/de_repair'
import { goDetail, swipeActPer } from '@/utils/permission'

//作用于新增或编辑后刷新页面数据
uni.$bus.useBusOn('de_wait', refreshList);

//页面header标题
const status_list = {
	'待接单': { text: '待接单', type: 'primary' },
	'维修中': { text: '维修中', type: 'warning' },
	'已完成': { text: '已完成', type: 'success' },
	'已取消': { text: '已取消', type: 'error' },
}
//页面跳转路径
const pageUrl = '/views/device/de_wait';

//查询参数
const queryParams = reactive({
});

//获取paging实例
const paging = ref(null)
const dataList = ref([])
//列表数据方法
function queryList(pageNo, pageSize) {
	const params = {
		page: pageNo,
		page_size: pageSize,
		...queryParams,
		status: '1,2'
	}
	deRepairApi.get_repair(params).then((res) => {
		paging.value?.complete(res.results);
	})
}

function hanldAct(id, key, text) {
	uni.showModal({
		title: '提示',
		content: '确定要接单吗？',
		success: (res) => {
			if (res.confirm) {
				deRepairApi.patch_repair({ status: key }, id).then(() => {
					uni.$u.toast(text)
					refreshList();
				})
			} else if (res.cancel) {
				console.log('用户点击取消');
			}
		}
	});
}

function waitDetail(id) {
	uni.navigateTo({
		url: `${pageUrl}/detail?type=wait&id=${id}`
	})
}

//刷新列表数据方法
function refreshList() {
	paging.value?.reload()
};
</script>

<style lang="scss"></style>